package com.wyx.suanfa;

import javax.swing.tree.TreeNode;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class convertBST {
    //给出二叉 搜索 树的根节点，该树的节点值各不相同，
    // 请你将其转换为累加树（Greater Sum Tree），
    // 使每个节点 node 的新值等于原树中大于或等于 node.val 的值之和。
    public static void main(String[] args) {
        int[] arr = new int[]{1,-1,0};
        new convertBST().subarraySum(arr,0);
    }

    public int subarraySum(int[] nums, int k) {
        int count = 0;
        for(int i = 0;i< nums.length;i++){
            int sum = 0;
            for(int j = i;j >= 0;j--){
                sum += nums[j];
                if(sum == k){
                    count++;
                }
            }
        }

        return count;
    }
}
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
/*
class Solution {
    int pre = 0;
    public TreeNode convertBST(TreeNode root) {
        traversal(root);
        return root;
    }

    void traversal(TreeNode root){
        if(root == null){
            return;
        }
        traversal(root.right);//右
        root.val += pre;//中
        pre = root.val;
        traversal(root.left);//左
        return;
    }
}*/
